
package com.scalar.chiptrack.proxy;


public class Proxy {

	public static void main(String args[]) {

		// PRINT ALL OPTIONS AND RETURN
		if (System.getProperty ("help") != null) {

			System.out.println ("\nUSAGE:\tjava [-Dhelp] [-Dproxy.data.outfile=<data_out_file>] [-Dproxy.port=<port>] [-Dproxy.log.level=<level>]\n");
			System.out.println ("\thelp - Prints out this message");
			System.out.println ("\tproxy.data.outfile - Specifies the file into which the data sent is stored (defaults to \"ChipTracProxy\")");
			System.out.println ("\tproxy.port - Port on which this proxy should be listening to (defaults to 80)");
			System.out.println ("\tproxy.log.level - log level (possible levels are 0, 1 or 2 (log everything) -- defaults to 0)\n\n");

			return;
		}


		// READ PORT PROPERTY (DEFAULT 80)
		int port = 80;
		try {
			port = Integer.parseInt (System.getProperty  ("proxy.port", "80"));
		}
		catch (NumberFormatException nfe) {
		}

		// READ LOG_LEVEL PROPERTY (DEFAULT 0)
		int logLevel = 0;
		try {
			logLevel = Integer.parseInt (System.getProperty ("proxy.log.level", "0"));
		}
		catch (NumberFormatException nfe) {
		}

		// READ FILE NAME TO DUMP DATA (DEFAULT ChipTracProxy)
		String dataOutFile = System.getProperty ("proxy.data.outfile", "ChipTracProxy");


		// open the log file
		Logger Log = new Logger("Proxy.log");

		// create a Proxy socket object
		ProxySocket Ps = new ProxySocket (port,   // iListenPortNumber
										  null,   // sDestIpAddress
										  0,      // iDestPortNumber
										  Log,
										  logLevel,
										  0,      // no data capturing
										  dataOutFile);

		// set the Proxy object running
		Ps.start() ;
		Ps = null ;
	}
}